package cn.stylefeng.guns.modular.order.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.order.entity.OrderPutDetailed;
import cn.stylefeng.guns.modular.order.mapper.OrderPutDetailedMapper;
import cn.stylefeng.guns.modular.order.model.params.OrderPutDetailedParam;
import cn.stylefeng.guns.modular.order.model.result.OrderPutDetailedResult;
import  cn.stylefeng.guns.modular.order.service.OrderPutDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 入库订单明细表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2019-07-03
 */
@Service
public class OrderPutDetailedServiceImpl extends ServiceImpl<OrderPutDetailedMapper, OrderPutDetailed> implements OrderPutDetailedService {

    @Override
    public void add(OrderPutDetailedParam param){
        OrderPutDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(OrderPutDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(OrderPutDetailedParam param){
        OrderPutDetailed oldEntity = getOldEntity(param);
        OrderPutDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public OrderPutDetailedResult findBySpec(OrderPutDetailedParam param){
        return null;
    }

    @Override
    public List<OrderPutDetailedResult> findListBySpec(OrderPutDetailedParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public List<OrderPutDetailedResult> findListBySpec2(OrderPutDetailedParam param){
        return this.baseMapper.findListBySpec2(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(OrderPutDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(OrderPutDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private OrderPutDetailed getOldEntity(OrderPutDetailedParam param) {
        return this.getById(getKey(param));
    }

    private OrderPutDetailed getEntity(OrderPutDetailedParam param) {
        OrderPutDetailed entity = new OrderPutDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<OrderPutDetailedResult> findListGroupGoodsidBySpec(OrderPutDetailedParam dParam) {
		return this.baseMapper.findListGroupGoodsidBySpec(dParam);
	}

	@Override
	public boolean saveBatchList(List<OrderPutDetailedParam> list) {
		return this.baseMapper.saveBatchList(list);
	}

	@Override
	public List<OrderPutDetailedResult> totalListBySpec(OrderPutDetailedParam param) {
		return this.baseMapper.totalListBySpec(param);
	}

	@Override
	public List<OrderPutDetailedResult> totalListByGandPSpec(OrderPutDetailedParam param) {
		return this.baseMapper.totalListByGandPSpec(param);
	}

}
